package com.ljx.mediatorPatternMode;


import lombok.Data;

import java.time.LocalDateTime;

/**
 *
 * 中介者模式（简单案例）
 *
 * @作者 LJX
 * @日期 2022/12/26 14:39
 */
public class MediatorPatternSimpleTest {

    public static void main(String[] args) {
        User 卢佳曦 = new User("卢佳曦");
        User SparrowJX = new User("SparrowJX");

        SparrowJX.sendMsg("佳曦你好！！！");
        卢佳曦.sendMsg("JX你好！！！");
    }

}

/**
 * 聊天室
 */
class ChatRoom{
    public static void showMessage(User user, String message){
        System.out.println(LocalDateTime.now().toString()
                + " [" + user.getName() +"] : " + message);
    }
}

/**
 * 用户类
 */
@Data
class User{
    String name;

    public User(String name) {
        this.name = name;
    }

    public void sendMsg(String msg){
        ChatRoom.showMessage(this, msg);
    }
}